#include "qt_test.h"
#include <QtWidgets/QApplication>
#include "SerialPort.h"
#include <curl/curl.h>
#include "MyThread.h"
#include "ConfigInfo.h"
#include "boost\lexical_cast.hpp"


size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t written = fwrite(ptr, size, nmemb, stream);
    return written;
}
/* NOTE: if you want this example to work on Windows with libcurl as a
   DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION.
   Failing to do so will give you a crash since a DLL may not use the
   variable's memory when passed in to it from an app like this. */ 
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
  curl_off_t nread;
  /* in real-world cases, this would probably get this data differently
     as this fread() stuff is exactly what the library already would do
     by default internally */ 
  size_t retcode = fread(ptr, size, nmemb,(FILE*) stream);
 
  nread = (curl_off_t)retcode;
 
  fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
          " bytes from file\n", nread);
  return retcode;
}
int main(int argc, char *argv[])
{
	/*QSerialPort port;
	port.setBaudRate(BAUD_9600);
	port.setParity(QSerialPort::NoParity);
	port.setStopBits(QSerialPort::TwoStop);
	port.isDataTerminalReady();*/
	/*CURL *curl;
    FILE *fp;
    CURLcode res;
    char *url = "http://cg3002-05-z.comp.nus.edu.sg/php/summary.php";
    char outfilename[FILENAME_MAX] = "testTakefile.txt";
    curl = curl_easy_init();
    if (curl) {
        fopen_s(&fp,outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);

        curl_easy_cleanup(curl);
        fclose(fp);
    }*/
	/*sql_Connector *contor=new sql_Connector();
	contor->start_Connect();
	contor->chooseDB(LOCAL_DB);
	//contor->insert_from_FILE("Inventory_5000.txt");
	contor->insert_Transaction_from_FILE("Trans_1000_20_9_11759.txt");
	delete contor;*/
	//contor->insert_Transaction_from_FILE("Trans_50_2_9_22639.txt");
	
	QApplication a(argc, argv);
	qt_test w;

	w.show();

	w.setFixedSize(APP_WIDTH,APP_HEIGHT);
	return a.exec();
	/*wchar_t *device=L"COM5";
	SerialPort *serial=new SerialPort();
	char buffer_send[128]={'<','\0'};
	char buffer[128];
	size_t len = strlen(buffer_send);
	serial->connect(device);
	while(1)
	{
		serial->sendArray(buffer_send, len);
		serial->getArray(buffer, strlen(buffer));
		
	}
	serial->disconnect();
	delete serial;*/


}
